<?php

/**
 * Created by PhpStorm.
 * User: linux
 * Date: 30/01/2018
 * Time: 2:29 PM
 */
namespace App\Advice;

use Go\Aop\Aspect;
use Go\Aop\Intercept\Invocation;
use Go\Aop\Intercept\MethodInvocation;
use Go\Lang\Annotation\Before;

class MonitorAspect implements Aspect
{
    /**
     * Method that will be called before real method
     *
     * @param MethodInvocation $invocation Invocation
     * @Before("execution(public App\Example\Example->*(*))")
     */
    public function beforeMethodExecution(MethodInvocation $invocation)
    {
        echo "调用了before\n";
//        $obj = $invocation->getThis();
//        echo 'Calling Before Interceptor for method: ',
//        is_object($obj) ? get_class($obj) : $obj,
//        $invocation->getMethod()->isStatic() ? '::' : '->',
//        $invocation->getMethod()->getName(),
//        '()',
//        ' with arguments: ',
//        json_encode($invocation->getArguments()),
//        "<br>\n";
    }

    /**
     * @Before("execution(public App\Example\Example::testInvocation(*))")
     */
    public function beforeMethodExecution2(MethodInvocation $invocation)
    {
        // 获取被切入的运行对象/类的信息
        $obj = $invocation->getThis();
        // 获取被切入方法信息
        $methond = $invocation->getMethod();
        // 获取被切入方法接收的参数信息
        $param = $invocation->getArguments();
    }
}